package lib

import(
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
)

type InfoCard struct {
	Name string `json:"name"`
	Idcard string	`json:"idcard"`

}

type CardCode struct {
	Code string `json:"code"`
	Message string `json:"message"`
	Data Data `json:"data"`
	SeqNo string `json:"seqNo"`
}
type Data struct {
	Result string `json:"result"`
}

func (this *CardCode)OutbQuery(name,card string ) (string,string,error)  {
	//fmt.Println(name,card)
	client := http.Client{}
	name1 := fmt.Sprintf("name=%s",name)
	card1 := fmt.Sprintf("idcard=%s",card)
	fmt.Println(name1+"&"+card1)
	request,err := http.NewRequest("POST", "http://checkone.market.alicloudapi.com/chinadatapay/1882",strings.NewReader(name1+"&"+card1))
	if err != nil{
		return "","",nil
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded") //设置Accept
	request.Header.Set("Authorization","APPCODE "+"a72b04b023f844cab5495a94239cce86")
	response, err := client.Do(request)
	//fmt.Println(response)
	if err != nil {
		return  "","",nil
	}
	defer response.Body.Close()
	body,err := ioutil.ReadAll(response.Body)
	fmt.Println(string(body),"-------")
	su := new(CardCode)
	err = json.Unmarshal(body, &su)
	if err != nil {
		return "","",nil
	}
	return su.Data.Result,su.Message,nil
}